<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>确认订单</p>
    </header>

    <!-- 订单信息部分 -->
    <div class="order-info">
      <h5>订单配送至：</h5>
      <div class="order-info-address">
        <p>沈阳市浑南区智慧四街1-121号</p>
        <i class="fa fa-angle-right"></i>
      </div>
      <p>某某先生 13656785432</p>
    </div>

    <h3>万家饺子（软件园E18店）</h3>

    <!-- 订单明细部分 -->
    <ul class="order-detailed">
      <li v-for="(item, index) in orderItems" :key="index">
        <div class="order-detailed-left">
          <img :src="item.image" :alt="item.name">
          <p>{{ item.name }} x {{ item.quantity }}</p>
        </div>
        <p>&#165;{{ item.price * item.quantity }}</p>
      </li>
    </ul>
    <div class="order-deliveryfee">
      <p>配送费</p>
      <p>&#165;{{ deliveryFee }}</p>
    </div>

    <!-- 合计部分 -->
    <div class="total">
      <div class="total-left">
        &#165;{{ totalPrice }}
      </div>
      <div class="total-right" @click="goToPayment">
        去支付
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router';

interface OrderItem {
  id: number;
  name: string;
  price: number;
  quantity: number;
  image: string;
}

const router = useRouter();

// 配送费
const deliveryFee = ref(3);

// 订单明细数据
const orderItems = ref<OrderItem[]>([
  { id: 1, name: '纯肉鲜肉（水饺）', price: 15, quantity: 2, image: '/img/sp01.png' },
  { id: 2, name: '玉米鲜肉（水饺）', price: 16, quantity: 1, image: '/img/sp02.png' }
]);

// 计算总价格（商品总价 + 配送费）
const totalPrice = computed(() => {
  const itemsTotal = orderItems.value.reduce((sum, item) => sum + (item.price * item.quantity), 0);
  return itemsTotal + deliveryFee.value;
});

// 去支付
const goToPayment = () => {
  router.push('/payment');
};
</script>

<style scoped>
.wrapper {
  padding-bottom: 14vw; /* 为底部合计部分留出空间 */
}

/* header部分 */
header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 12vw;
  background-color: #0097FF;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #fff;
  font-size: 4.5vw;
  z-index: 100;
}

/* 订单信息部分 */
.order-info {
  margin-top: 12vw;
  padding: 4vw;
  background-color: #fff;
  border-bottom: solid 1px #EEE;
}

.order-info h5 {
  font-size: 4vw;
  color: #666;
  margin-bottom: 2vw;
}

.order-info-address {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2vw;
}

.order-info-address p {
  font-size: 4.5vw;
  font-weight: bold;
}

.order-info-address i {
  font-size: 5vw;
  color: #999;
}

.order-info > p {
  font-size: 3.8vw;
  color: #666;
}

/* 商家名称 */
h3 {
  padding: 4vw;
  font-size: 4.5vw;
  background-color: #fff;
  border-bottom: solid 1px #EEE;
}

/* 订单明细部分 */
.order-detailed {
  padding: 4vw;
  background-color: #fff;
  border-bottom: solid 1px #EEE;
}

.order-detailed li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3vw 0;
}

.order-detailed-left {
  display: flex;
  align-items: center;
}

.order-detailed-left img {
  width: 15vw;
  height: 15vw;
  margin-right: 4vw;
}

.order-detailed-left p {
  font-size: 4vw;
}

.order-detailed li > p {
  font-size: 4vw;
  font-weight: bold;
}

/* 配送费部分 */
.order-deliveryfee {
  display: flex;
  justify-content: space-between;
  padding: 4vw;
  background-color: #fff;
  border-bottom: solid 1px #EEE;
}

.order-deliveryfee p {
  font-size: 4vw;
}

.order-deliveryfee p:last-child {
  font-weight: bold;
}

/* 合计部分 */
.total {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 14vw;
  background-color: #fff;
  display: flex;
  border-top: solid 1px #DDD;
  z-index: 100;
}

.total-left {
  flex: 1;
  display: flex;
  align-items: center;
  padding-left: 4vw;
  font-size: 5vw;
  font-weight: bold;
  color: #FF6600;
}

.total-right {
  width: 30vw;
  height: 100%;
  background-color: #38CA73;
  color: #fff;
  font-size: 4.5vw;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
</style>